1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.GutterRenderer;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.AccessibleIF;
30 private import gtk.AccessibleT;
31 private import gtk.BuildableIF;
32 private import gtk.BuildableT;
33 private import gtk.ConstraintTargetIF;
34 private import gtk.ConstraintTargetT;
35 private import gtk.TextIter;
36 private import gtk.Widget;
37 private import sourceview.Buffer;
38 private import sourceview.View;
39 private import sourceview.c.functions;
40 public  import sourceview.c.types;
41 private import std.algorithm;
42 
43 
44 /**
45  * Gutter cell renderer.
46  * 
47  * A `GtkSourceGutterRenderer` represents a column in a [class@Gutter]. The
48  * column contains one cell for each visible line of the [class@Gtk.TextBuffer]. Due to
49  * text wrapping, a cell can thus span multiple lines of the [class@Gtk.TextView]. In
50  * this case, [enum@GutterRendererAlignmentMode] controls the alignment of
51  * the cell.
52  * 
53  * The gutter renderer is a [class@Gtk.Widget] and is measured using the normal widget
54  * measurement facilities. The width of the gutter will be determined by the
55  * measurements of the gutter renderers.
56  * 
57  * The width of a gutter renderer generally takes into account the entire text
58  * buffer. For instance, to display the line numbers, if the buffer contains 100
59  * lines, the gutter renderer will always set its width such as three digits can
60  * be printed, even if only the first 20 lines are shown. Another strategy is to
61  * take into account only the visible lines.  In this case, only two digits are
62  * necessary to display the line numbers of the first 20 lines. To take another
63  * example, the gutter renderer for [class@Mark]s doesn't need to take
64  * into account the text buffer to announce its width. It only depends on the
65  * icons size displayed in the gutter column.
66  * 
67  * When the available size to render a cell is greater than the required size to
68  * render the cell contents, the cell contents can be aligned horizontally and
69  * vertically with [method@GutterRenderer.set_alignment_mode].
70  * 
71  * The cells rendering occurs using [vfunc@Gtk.Widget.snapshot]. Implementations
72  * should use `gtk_source_gutter_renderer_get_lines()` to retrieve information
73  * about the lines to be rendered. To help with aligning content which takes
74  * into account the padding and alignment of a cell, implementations may call
75  * [method@GutterRenderer.align_cell] for a given line number with the
76  * width and height measurement of the content they width to render.
77  */
78 public class GutterRenderer : Widget
79 {
80 	/** the main Gtk struct */
81 	protected GtkSourceGutterRenderer* gtkSourceGutterRenderer;
82 
83 	/** Get the main Gtk struct */
84 	public GtkSourceGutterRenderer* getGutterRendererStruct(bool transferOwnership = false)
85 	{
86 		if (transferOwnership)
87 			ownedRef = false;
88 		return gtkSourceGutterRenderer;
89 	}
90 
91 	/** the main Gtk struct as a void* */
92 	protected override void* getStruct()
93 	{
94 		return cast(void*)gtkSourceGutterRenderer;
95 	}
96 
97 	/**
98 	 * Sets our main struct and passes it to the parent class.
99 	 */
100 	public this (GtkSourceGutterRenderer* gtkSourceGutterRenderer, bool ownedRef = false)
101 	{
102 		this.gtkSourceGutterRenderer = gtkSourceGutterRenderer;
103 		super(cast(GtkWidget*)gtkSourceGutterRenderer, ownedRef);
104 	}
105 
106 
107 	/** */
108 	public static GType getType()
109 	{
110 		return gtk_source_gutter_renderer_get_type();
111 	}
112 
113 	/**
114 	 * Emits the [signal@GutterRenderer::activate] signal of the renderer. This is
115 	 * called from [class@Gutter] and should never have to be called manually.
116 	 *
117 	 * Params:
118 	 *     iter = a #GtkTextIter at the start of the line where the renderer is activated
119 	 *     area = a #GdkRectangle of the cell area where the renderer is activated
120 	 *     button = the button that was pressed
121 	 *     state = a #GdkModifierType
122 	 *     nPresses = the number of button presses
123 	 */
124 	public void activate(TextIter iter, GdkRectangle* area, uint button, GdkModifierType state, int nPresses)
125 	{
126 		gtk_source_gutter_renderer_activate(gtkSourceGutterRenderer, (iter is null) ? null : iter.getTextIterStruct(), area, button, state, nPresses);
127 	}
128 
129 	/**
130 	 * Locates where to render content that is @width x @height based on
131 	 * the renderers alignment and padding.
132 	 *
133 	 * The location will be placed into @x and @y and is relative to the
134 	 * renderer's coordinates.
135 	 *
136 	 * It is encouraged that renderers use this function when snappshotting
137 	 * to ensure consistent placement of their contents.
138 	 *
139 	 * Params:
140 	 *     line = the line number for content
141 	 *     width = the width of the content to draw
142 	 *     height = the height of the content to draw
143 	 *     x = the X position to render the content
144 	 *     y = the Y position to render the content
145 	 */
146 	public void alignCell(uint line, float width, float height, out float x, out float y)
147 	{
148 		gtk_source_gutter_renderer_align_cell(gtkSourceGutterRenderer, line, width, height, &x, &y);
149 	}
150 
151 	/**
152 	 * Get the alignment mode.
153 	 *
154 	 * The alignment mode describes the manner in which the
155 	 * renderer is aligned (see [property@GutterRenderer:xalign] and
156 	 * [property@GutterRenderer:yalign]).
157 	 *
158 	 * Returns: a #GtkSourceGutterRendererAlignmentMode
159 	 */
160 	public GtkSourceGutterRendererAlignmentMode getAlignmentMode()
161 	{
162 		return gtk_source_gutter_renderer_get_alignment_mode(gtkSourceGutterRenderer);
163 	}
164 
165 	/**
166 	 * Gets the [class@Buffer] for which the gutter renderer is drawing.
167 	 *
168 	 * Returns: a #GtkTextBuffer or %NULL
169 	 */
170 	public Buffer getBuffer()
171 	{
172 		auto __p = gtk_source_gutter_renderer_get_buffer(gtkSourceGutterRenderer);
173 
174 		if(__p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(Buffer)(cast(GtkSourceBuffer*) __p);
180 	}
181 
182 	/**
183 	 * Get the view associated to the gutter renderer
184 	 *
185 	 * Returns: a #GtkSourceView
186 	 */
187 	public View getView()
188 	{
189 		auto __p = gtk_source_gutter_renderer_get_view(gtkSourceGutterRenderer);
190 
191 		if(__p is null)
192 		{
193 			return null;
194 		}
195 
196 		return ObjectG.getDObject!(View)(cast(GtkSourceView*) __p);
197 	}
198 
199 	/**
200 	 * Gets the `xalign` property.
201 	 *
202 	 * This may be used to adjust where within the cell rectangle the renderer will draw.
203 	 */
204 	public float getXalign()
205 	{
206 		return gtk_source_gutter_renderer_get_xalign(gtkSourceGutterRenderer);
207 	}
208 
209 	/**
210 	 * Gets the `xpad` property.
211 	 *
212 	 * This may be used to adjust the cell rectangle that the renderer will use to draw.
213 	 */
214 	public int getXpad()
215 	{
216 		return gtk_source_gutter_renderer_get_xpad(gtkSourceGutterRenderer);
217 	}
218 
219 	/**
220 	 * Gets the `yalign` property.
221 	 *
222 	 * This may be used to adjust where within the cell rectangle the renderer will draw.
223 	 */
224 	public float getYalign()
225 	{
226 		return gtk_source_gutter_renderer_get_yalign(gtkSourceGutterRenderer);
227 	}
228 
229 	/**
230 	 * Gets the `ypad` property.
231 	 *
232 	 * This may be used to adjust the cell rectangle that the renderer will use to draw.
233 	 */
234 	public int getYpad()
235 	{
236 		return gtk_source_gutter_renderer_get_ypad(gtkSourceGutterRenderer);
237 	}
238 
239 	/**
240 	 * Get whether the renderer is activatable at the location provided. This is
241 	 * called from [class@Gutter] to determine whether a renderer is activatable
242 	 * using the mouse pointer.
243 	 *
244 	 * Params:
245 	 *     iter = a #GtkTextIter at the start of the line to be activated
246 	 *     area = a #GdkRectangle of the cell area to be activated
247 	 *
248 	 * Returns: %TRUE if the renderer can be activated, %FALSE otherwise
249 	 */
250 	public bool queryActivatable(TextIter iter, GdkRectangle* area)
251 	{
252 		return gtk_source_gutter_renderer_query_activatable(gtkSourceGutterRenderer, (iter is null) ? null : iter.getTextIterStruct(), area) != 0;
253 	}
254 
255 	/**
256 	 * Set the alignment mode. The alignment mode describes the manner in which the
257 	 * renderer is aligned (see [property@GutterRenderer:xalign] and
258 	 * [property@GutterRenderer:yalign]).
259 	 *
260 	 * Params:
261 	 *     mode = a #GtkSourceGutterRendererAlignmentMode
262 	 */
263 	public void setAlignmentMode(GtkSourceGutterRendererAlignmentMode mode)
264 	{
265 		gtk_source_gutter_renderer_set_alignment_mode(gtkSourceGutterRenderer, mode);
266 	}
267 
268 	/**
269 	 * Adjusts the `xalign` property.
270 	 *
271 	 * This may be used to adjust where within the cell rectangle the renderer will draw.
272 	 *
273 	 * Params:
274 	 *     xalign = the Y padding for the drawing cell
275 	 */
276 	public void setXalign(float xalign)
277 	{
278 		gtk_source_gutter_renderer_set_xalign(gtkSourceGutterRenderer, xalign);
279 	}
280 
281 	/**
282 	 * Adjusts the `xpad` property.
283 	 *
284 	 * This may be used to adjust the cell rectangle that the renderer will use to draw.
285 	 *
286 	 * Params:
287 	 *     xpad = the Y padding for the drawing cell
288 	 */
289 	public void setXpad(int xpad)
290 	{
291 		gtk_source_gutter_renderer_set_xpad(gtkSourceGutterRenderer, xpad);
292 	}
293 
294 	/**
295 	 * Adjusts the `yalign` property.
296 	 *
297 	 * This may be used to adjust where within the cell rectangle the renderer will draw.
298 	 *
299 	 * Params:
300 	 *     yalign = the Y padding for the drawing cell
301 	 */
302 	public void setYalign(float yalign)
303 	{
304 		gtk_source_gutter_renderer_set_yalign(gtkSourceGutterRenderer, yalign);
305 	}
306 
307 	/**
308 	 * Adjusts the `ypad` property.
309 	 *
310 	 * This may be used to adjust the cell rectangle that the renderer will use to draw.
311 	 *
312 	 * Params:
313 	 *     ypad = the Y padding for the drawing cell
314 	 */
315 	public void setYpad(int ypad)
316 	{
317 		gtk_source_gutter_renderer_set_ypad(gtkSourceGutterRenderer, ypad);
318 	}
319 
320 	/**
321 	 * The signal is emitted when the renderer is activated.
322 	 *
323 	 * Params:
324 	 *     iter = a #GtkTextIter
325 	 *     area = a #GdkRectangle
326 	 *     button = the button that was pressed
327 	 *     state = a #GdkModifierType of state
328 	 *     nPresses = the number of button presses
329 	 */
330 	gulong addOnActivate(void delegate(TextIter, GdkRectangle*, uint, GdkModifierType, int, GutterRenderer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
331 	{
332 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
333 	}
334 
335 	/**
336 	 * The signal is emitted when the renderer can possibly be activated.
337 	 *
338 	 * Params:
339 	 *     iter = a #GtkTextIter
340 	 *     area = a #GdkRectangle
341 	 */
342 	gulong addOnQueryActivatable(bool delegate(TextIter, GdkRectangle*, GutterRenderer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
343 	{
344 		return Signals.connect(this, "query-activatable", dlg, connectFlags ^ ConnectFlags.SWAPPED);
345 	}
346 
347 	/** */
348 	gulong addOnQueryData(void delegate(ObjectG, uint, GutterRenderer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
349 	{
350 		return Signals.connect(this, "query-data", dlg, connectFlags ^ ConnectFlags.SWAPPED);
351 	}
352 }